package br.com.portalecbahia;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
import br.com.portalecbahia.connectionservices.SynchronizeAudio;
import br.com.portalecbahia.customize.PullToRefreshListView;
import br.com.portalecbahia.listner.MediaListeners;
import br.com.portalecbahia.listner.OnCompleateAudio;
import br.com.portalecbahia.util.PortalECBahiaUtil;

import com.google.analytics.tracking.android.EasyTracker;

public class SymbolActivity extends Activity implements OnCompleateAudio{

	private Intent serviceAudio;
	ImageButton signalIMG;

	ImageButton signal2IMG;
	
	boolean hino = false;
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
       
        super.setContentView(R.layout.symbol);
        EasyTracker.getInstance().setContext(this);
        signalIMG = (ImageButton)findViewById(R.id.signalIMG);
        signal2IMG = (ImageButton)findViewById(R.id.signal2IMG);

    }
    
    @Override
    public void onStart() {
      super.onStart();
      EasyTracker.getInstance().activityStart(this); // Add this method.
    }

    @Override
    public void onStop() {
      super.onStop();
      EasyTracker.getInstance().activityStop(this); // Add this method.
    }
    
    public void playHino(View view){
    	if(serviceAudio==null){
			if("".equals(PortalECBahiaUtil.AUDIO_PLAYING)){
				
				
				PortalECBahiaUtil.AUDIO_PLAYING = "http://k003.kiwi6.com/hotlink/1tkf1adt3s/hino_do_bahia.mp3";
				 
				
				serviceAudio = new Intent(this, SynchronizeAudio.class);
				SynchronizeAudio.listeners = this;
				startService(serviceAudio);
		
				signalIMG.setImageResource(R.drawable.audio_play);
				hino = true;
				
			}
    	}else{
    	
    		if(hino)
    			signalIMG.setImageResource(R.drawable.audio_off);
    			else
    				signal2IMG.setImageResource(R.drawable.audio_off);
    		stopService(serviceAudio); 
    	
		}
    }
    
    public void playGrito(View view){
    	if(serviceAudio==null){
			if("".equals(PortalECBahiaUtil.AUDIO_PLAYING)){
				
				
				PortalECBahiaUtil.AUDIO_PLAYING = "http://k003.kiwi6.com/hotlink/3y8uo8hhh8/bora_bahe_a_minha_porra.mp3";
				 
				
				serviceAudio = new Intent(this, SynchronizeAudio.class);
				SynchronizeAudio.listeners = this;
				startService(serviceAudio);
				hino = false;
				signal2IMG.setImageResource(R.drawable.audio_play);
				
			}
    	}else{
    		if(hino)
    			signalIMG.setImageResource(R.drawable.audio_off);
    			else
    				signal2IMG.setImageResource(R.drawable.audio_off);
				stopService(serviceAudio); 
    		

		}
    }
    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
    	super.onDestroy();
    	if(serviceAudio!=null)
		stopService(serviceAudio); 

    }


	@Override
	public void onCompleateAudio() {
		PortalECBahiaUtil.AUDIO_PLAYING = "";
		if(hino)
		signalIMG.setImageResource(R.drawable.audio_off);
		else
			signal2IMG.setImageResource(R.drawable.audio_off);
		
		serviceAudio = null;
	}	
		

	

    
}
